package com.jdbc.senior;

import com.jdbc.senior.dao.impl.EmployeeDaoImpl;
import com.jdbc.senior.pojo.Employee;
import com.jdbc.senior.util.JDBCUtil;
import com.jdbc.senior.util.JDBCUtilV2;
import org.junit.Test;

import java.sql.Connection;
import java.util.List;

public class JDBCUtilTest {
    @Test
    public void test() {
        Connection connection = JDBCUtil.getConnection();
        System.out.println(connection);
        JDBCUtil.release(connection);
    }

    @Test
    public void test2() {
        Connection connection = JDBCUtilV2.getConnection();
        Connection connection2 = JDBCUtilV2.getConnection();
        Connection connection3 = JDBCUtilV2.getConnection();

        System.out.println(connection);
        System.out.println(connection2);
        System.out.println(connection3);

        JDBCUtilV2.release();
    }

    @Test
    public void test3() {
        EmployeeDaoImpl employeeDao = new EmployeeDaoImpl();
        List<Employee> employees = employeeDao.selectAll();
        for (Employee employee : employees) {
            System.out.println(employee);
        }
    }

    @Test
    public void test4() {
        EmployeeDaoImpl employeeDao = new EmployeeDaoImpl();
        Employee employee = employeeDao.selectById(2);
        System.out.println(employee);
    }

    @Test
    public void test5() {
        EmployeeDaoImpl employeeDao = new EmployeeDaoImpl();
        Employee employee = new Employee(null, "mike", 1756.8, 45);
        int insert = employeeDao.insert(employee);
        System.out.println(insert);
    }
}
